package com.niit.ontouch;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    EditText result;
    LinearLayout testtest;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        result = findViewById(R.id.touch);
        testtest = findViewById(R.id.test);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event){
        String position = "";
        if(event.getAction() == MotionEvent.ACTION_MOVE){
            Log.i("test","ACTION_MOVE");
            position = "";
            float x = event.getX();
            float y = event.getY();
            position = "X="+x+",Y="+y;
            result.setText(position);
            testtest.setBackground(getResources().getDrawable(R.drawable.img01));
            result.setBackgroundColor(Color.parseColor("#0000FF"));
        }else if(event.getAction() == MotionEvent.ACTION_UP){
            Log.i("test","ACTION_UP");
            testtest.setBackground(getResources().getDrawable(R.drawable.img02));
            result.setBackgroundColor(Color.parseColor("#DC143C"));
        }else if(event.getAction() == MotionEvent.ACTION_DOWN){
            Log.i("test","ACTION_DOWN");
            position = "";
            float x = event.getX();
            float y = event.getY();
            position = "X="+x+",Y="+y;
            result.setText(position);
            testtest.setBackground(getResources().getDrawable(R.drawable.img03));
            result.setBackgroundColor(Color.parseColor("#DDA0DD"));
        }
        return super.onTouchEvent(event);
    }

}
